package org.igorrogic.jndi_consumer;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;

public class ObjectConsumer {
    public static void main(String[] args) {
        Context context = null;
        try {
            Hashtable env = new Hashtable();
            /*env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
            context = new InitialContext(env);*/
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
            System.setProperty(Context.PROVIDER_URL, "rmi://127.0.0.1:3001");
            context = new InitialContext();
            //System.out.println(env.getClass().getName());
            context.lookup("rmi://127.0.0.1:3001/jordanx");
            //Person jordan = (Person) context.lookup("rmi://127.0.0.1:3001/jordan");
            //System.out.println("jordan = " + jordan.getName());
        } catch (NamingException nex) {
            System.out.println("Initial context couldn't have been created.");
            nex.printStackTrace();
        } finally {
            try {
                context.close();
            } catch (NamingException nex) {
                System.out.println("Initial context couldn't have been closed.");
                nex.printStackTrace();
            }
        }
    }
}
